package com.gurun.camera.device.model;

import com.danale.player.SPlayer;
import com.danale.player.content.DAudioRecord;
import com.danale.player.content.UniqueId;
import com.danale.player.entity.ChannelDevice;
import com.danale.player.entity.CloudRecordDevice;
import com.danale.player.entity.LocalRecord;
import com.danale.player.entity.MultiChannelDevice;
import com.danale.player.entity.SdRecordDevice;
import com.danale.player.listener.MediaState;
import com.danale.player.window.ScreenType;
import com.danale.sdk.platform.entity.device.Device;
import com.danale.sdk.platform.entity.v3.PushMsg;
import com.gurun.camera.device.bean.VideoDevice;
import com.gurun.camera.device.constant.VideoDataType;
import com.gurun.camera.device.listener.OnCallbackListener;
import com.gurun.camera.device.listener.OnDeviceCallback;
import com.gurun.camera.device.listener.OnMediaStateListener;
import com.gurun.camera.device.listener.OnPlayerClickListener;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public abstract class ControlManager {
    protected SPlayer sPlayer;
    protected IVideoPlayModel videoPlayModel;
    protected VideoDataType videoDataType;
    protected VideoDevice currentVideoDevice;
    /**
     * 播放器状态回调
     */
    protected OnMediaStateListener onMediaStateListener;
    /**
     * 点击屏幕的回调（单击双击）
     */
    protected OnPlayerClickListener onPlayerClickListener;
    protected OnCallbackListener onCallbackListener;
    protected OnDeviceCallback onDeviceCallback;
    protected CloudRecordDevice cloudRecordDevice;
    protected SdRecordDevice sdRecordDevice;
    protected LocalRecord localRecord;
    protected Device device;
    protected int[] channels;
    protected ChannelDevice channelDevice;
    protected MultiChannelDevice multiChannelDevice;

    
    protected String id;
    protected String cloud_id;
    protected String sd_id;
    protected String local_id;
    protected UniqueId uniqueId;
    protected boolean isCardPlayer;

    public void setOnDeviceCallback(OnDeviceCallback onDeviceCallback) {
        this.onDeviceCallback = onDeviceCallback;
    }

    public void setOnCallbackListener(OnCallbackListener onCallbackListener) {
        this.onCallbackListener = onCallbackListener;
    }

    public void setOnPlayerClickListener(OnPlayerClickListener onPlayerClickListener) {
        this.onPlayerClickListener = onPlayerClickListener;
    }

    public void setOnMediaStateListener(OnMediaStateListener listener){
        this.onMediaStateListener = listener;
    }

    public void setCurrentVideoDevice(VideoDevice currentVideoDevice) {
        this.currentVideoDevice = currentVideoDevice;
    }

    TimerTask recordTimerTask;
    Timer recordTimer;
    int recordCount;

    protected void startTimer(){
        if (recordTimerTask == null){
            recordTimerTask = new TimerTask() {
                @Override
                public void run() {
                    recordCount++;
                    onMediaStateListener.onRecordStateChange(MediaState.RUNNING, recordCount, "");
                }
            };
        }

        if (recordTimer == null){
            recordTimer = new Timer();
            recordTimer.schedule(recordTimerTask, 0L, 1000L);
        }
    }

    protected void stopTimer(){
        recordCount = 0;
        if (recordTimerTask != null){
            recordTimerTask.cancel();
            recordTimerTask = null;
        }
        if (recordTimer != null){
            recordTimer.cancel();
            recordTimer = null;
        }
    }
    public void initPlay(int width, float factor, ScreenType screenType){}
    public void setId(String id) {
        this.id = id;
    }

    public void updateData(String device_id){}

    public void prepare(){}
    public void release(){}
    public void stopRecord(){}
    public void startVideo(){}
    public void startVideo(boolean visible){}
    public void clickAudio(){}
    public void clickTalk(){}
    public void clickRecord(){}
    public void startTalk(){}
    public void stopTalk(){}
    public void startAudio(){}
    public void stopAudio(){}
    public void setIsSilence(boolean isSilence){}
    public void stopVideo(){}
    public void stopVideo(boolean closeConnection){}
    public void stopVideoData(){}
    public void capture(){}
    public void pause(){}
    public void resume(){}

    /**
     * 选中屏幕
     * @param device_id
     */
    public void selectSubScreen(String device_id){}

    /**
     * 切换屏幕状态（分屏或者整屏）
     */
    public void switchScreenState(){}
    public int getDuration(){
        return 0;
    };
    public int getCurrentPosition(){
        return 0;}
    public void seekTo(int misc){}

    /**
     * 设置云录像的数据
     * @param device
     */
    public void setCloudRecordData(CloudRecordDevice device){}

    /**
     * 设置SD卡录像的数据
     * @param device
     */
    public void setSDRecordData(SdRecordDevice device){}

    /**
     * 设置本地录像的数据
     * @param file_path
     */
    public void setLocalRecordData(String file_path){}

    /**
     * 设置不规则分屏的通道布局
     * @param device
     */
    public void setMultiChanDevice(MultiChannelDevice device){}

    /**
     * 获取sd卡状态
     */
    public void getSdState(){}

    /**
     * 获取SD卡录像列表（指定通道的）
     * @param timestamp
     * @param channel
     */
    public void getSDRecordList(long timestamp, int channel){}

    /**
     * 获取SD卡录像列表
     * @param timestamp
     */
    public void getSDRecordList(long timestamp){}

    /**
     * 获取SD卡指定时间的录像的信息（指定通道的）
     * @param timestamp
     * @param channel
     */
    public void getSDRecordPlayInfo(long timestamp, int channel){}

    /**
     * 获取SD卡指定时间的录像的信息
     * @param timestamp
     */
    public void getSDRecordPlayInfo(long timestamp){}

    /**
     * 获取云服务状态
     */
    public void getCloudState(){}

    /**
     * 获取云服务状态（一组设备的）
     * @param devices
     */
    public void getCloudStateByList(List<Device> devices){}

    /**
     * 获取云录像列表（指定通道的）
     * @param timestamp
     * @param channel
     */
    public void getCloudRecordList(long timestamp, int channel){}

    /**
     * 获取云录像列表
     * @param timestamp
     */
    public void getCloudRecordList(long timestamp){}

    /**
     * 获取指定时间的云录像信息（指定通道的）
     * @param timestamp
     * @param channel
     */
    public void getCloudRecordPlayInfo(long timestamp, int channel){}

    public void getCloudRecordPlayInfoByPushMsg(PushMsg pushMsg){}
    /**
     * 获取指定时间的云录像信息
     * @param timestamp
     */
    public void getCloudRecordPlayInfo(long timestamp){}

    /**
     * 获取不规则分屏的通道布局
     */
    public void getLayout(){}

    /**
     * 设置当前通道号
     * @param channel
     */
    public void setChannel(int channel){}

    /**
     *
     * @param channel
     */
    public void changeChannel(int[] channel){}

    /**
     * 控制车库门
     * @param on
     */
    public void controlGarageDoor(int on){}

    /**
     * 设置录像的数据回调
     * @param callback
     */
    public void setRecordCallback(DAudioRecord.RecordCallback callback){}
}
